// import jfxy from './jfxy/jfxy.vue'
export default {
	name: 'addPosition',
	// components: {
	// 	jfxy
	// },
	data() {
		return {
			disable: false,
			cname: '',
			checkshow: true,
			xyshow: false,
			start: {
				start: '00:00',
				step: '00:30',
				end: '24:00'
			},
			status: '',
			welfares: [],
			talentType: [], // 人才类型
			tempTalentType: [],
			// 选择的薪资待遇对象
			salaryObj: '',
			tempCity: '',
			tempArea: '',
			ishighquality: '',
			formInline: {
				remark1: '',
				type: '',
				userid: '',
				salaryStructure: '',
				companyid: this.$route.query.id, // 公司编码
				positionid: '', // 岗位编码 新增时为空
				province: '',
				city: '',
				area: '',
				address: '', // 工作地点
				industrytype: '', // 所属行业编码
				tradeid: '', // 职能编码
				positionname: '', // 职位名称
				talenttype: '', // 岗位类型编码
				recruitment: '', // 招聘人数
				qualification: '', // 学历编码
				worklife: '', // 工作年限编码
				offer: '', // 薪资待遇区间
				maxwage: '', // 最高薪资
				miniwage: '', // 最低薪资
				personalintegral: '', // 优惠前单人服务费(服务费用)
				discountpersonal: '', // 优惠后单人服务费
				positionintegral: '', // 优惠前总费用
				discountposition: '', // 优惠后总费用
				entryday: '', // 在职保障天数
				welfare: '', // 职位福利
				jobcontent: '', // 岗位职责
				workduty: '', // 任职要求
				paytype: '1', // 支付方式 1-> 直接支付 2-> 免费体验
				returntype: '0', // 积分返还类型 0-> 一次性返还(默认) 1-> 每月返还
				discount: 1,
				typeDisplay: false, //是否人才类型选择
				selectDistricts: [],
				selectIndustrytypes: [],
				selectFunctions: [],
				minage: '',
				maxage: '',
				worktime: '', //工作时间段
				workday: '', //工作天数 时薪短期-数字天数 长期-每周工作几个工作日 
				hourlyState: '1', //工作性质(时薪时用长期还是短期1-长期,2-短期)
				workingHoursList: [], //具体工作时间段["2020-08-21","2020-08-22"]
				wagetype: '1',
				welfare: '',
				startTime: '',
				endTime: '',
				hourlywage: '', //时薪
				checked: false,
				positionType: 1, // 岗位类型（固定传1）
			},
			checkList: [], //时薪长期选择的日期
			demonstration: [], //时薪短期选择的日期
			isShow: true,
			worktime: '', //时间
			//薪资类型
			currentEntryday: '',
			startHour: '',
			startmark: '',
			endHour: '',
			endmark: '',
			wagetypeOption: [{
					value: '1',
					label: '月薪'
				},
				{
					value: '2',
					label: '时薪'
				}
			],
			nowSave: 0,
			agelist: [], //最小年龄段
			maxagelist: [], //最大年龄段
			areaList: [],
			// 地市 级联选择器
			districtOption: [],
			districtProps: {
				value: 'code',
				label: 'name',
				children: 'subLevelModelList'
			},
			// 行业 级联选择器
			industrytypeOption: [],
			industrytypeProps: {
				value: 'code',
				label: 'name',
				children: 'subLevelModelList'
			},
			// 职能 级联选择器
			functionOption: [],
			functionProps: {
				value: 'code',
				label: 'name',
				children: 'subLevelModelList'
			},
			educationList: [], // 学历列表
			WorkYearsList: [], // 工作年限列表
			salaryList: [], // 薪资待遇列表
			welfareList: [], // 福利待遇列表

			flag: true,
			// custom:true,
			miniSalary: 5,
			maxSalary: 6,
			disabledmax: false,
			times: '',
			timeNum: '',
			hide: 'false',
			headerTitle: '发布岗位',
			rules: {
				selectDistricts: [{
					required: true,
					message: '请选择地市',
					trigger: 'change'
				}],
				address: [{
					required: true,
					message: '请填写工作地点',
					trigger: 'blur'
				}],
				selectFunctions: [{
					required: true,
					message: '请选择职能',
					trigger: 'change'
				}],
				selectIndustrytypes: [{
					required: true,
					message: '请选择所属行业',
					trigger: 'change'
				}],
				positionname: [{
					required: true,
					message: '请输入职位',
					trigger: 'blur'
				}],
				talenttype: [{
					required: true,
					message: '请选择岗位类型',
					trigger: 'change'
				}],
				recruitment: [{
					// type: "number",
					required: true,
					message: '请输入招聘人数',
					trigger: 'blur'
				}],
				qualification: [{
					required: true,
					message: '请选择学历要求',
					trigger: 'change'
				}],
				worklife: [{
					required: true,
					message: '请选择工作经验',
					trigger: 'change'
				}],
				offer: [{
					required: true,
					message: '请选择薪资待遇',
					trigger: 'blur'
				}],
				entryday: [{
					required: true,
					message: '请选择保障天数',
					trigger: 'blur'
				}],
				personalintegral: [{
					required: true,
					message: '请输入服务费用',
					trigger: 'blur'
				}],
				welfare: [{
					required: true,
					message: '请选择福利待遇',
					trigger: 'blur'
				}],
				jobcontent: [{
					required: true,
					message: '请输入岗位职责',
					trigger: 'blur'
				}],

				salaryStructure: [{
					required: false,
					message: '请输入岗位职责',
					trigger: 'blur'
				}],
				// workduty: [
				//   {
				//     required: true,
				//     message: '请输入任职要求',
				//     trigger: 'blur'
				//   }
				// ],
				paytype: [{
					required: true,
					message: '请选择付费类型',
					trigger: 'change'
				}],
				minage: [{
					required: true,
					message: '请选择年龄范围',
					trigger: 'change'
				}],
				maxage: [{
					required: true,
					message: '请选择年龄范围',
					trigger: 'change'
				}],
				wagetype: [{
					required: true,
					message: '请选择薪资类型',
					trigger: 'change'
				}],
				startTime: [{
					required: true,
					message: '请选择开始时间段',
					trigger: 'change'
				}],
				endTime: [{
					required: true,
					message: '请选择结束时间段',
					trigger: 'change'
				}],
				workday: [{
					required: true,
					message: '请输入工作天数',
					trigger: 'blur'
				}],
				hourlywage: [{
					required: true,
					message: '请输入薪资待遇',
					trigger: 'blur'
				}]
			},
			// 我的岗位建模的东西
			direction: [{
					name: 'caozuo',
					value: 0
				},
				{
					name: 'guihua',
					value: 0
				},
				{
					name: 'jineng',
					value: 0
				},
				{
					name: 'shiwu',
					value: 0
				},
				{
					name: 'yishu',
					value: 0
				},
				{
					name: 'faming',
					value: 0
				},
				{
					name: 'renwu',
					value: 0
				},
				{
					name: 'fuwu',
					value: 0
				},
				{
					name: 'guankong',
					value: 0
				},
				{
					name: 'kaituo',
					value: 0
				},
				{
					name: 'jiaoji',
					value: 0
				},
				{
					name: 'yingxiang',
					value: 0
				}
			],
			// 动机分析的值
			motive: [{
					name: 'caifu',
					value: 0
				},
				{
					name: 'jiankang',
					value: 0
				},
				{
					name: 'xiangshou',
					value: 0
				},
				{
					name: 'gongzuo',
					value: 0
				},
				{
					name: 'quanli',
					value: 0
				},
				{
					name: 'chuangxin',
					value: 0
				},
				{
					name: "qinggan",
					value: 0
				},
				{
					name: 'rongyu',
					value: 0
				}
			],
			// 上面的演示条
			activeName: '1',
			value: [0, 100],
			marks: {
				0: {
					style: {
						color: '#FFCC00'
					},
					label: this.$createElement('strong', '0')
				},
				20: {
					style: {
						color: '#FF9900'
					},
					label: this.$createElement('strong', '低')
				},
				40: {
					style: {
						color: '#FF6600'
					},
					label: this.$createElement('strong', '40')
				},
				50: {
					style: {
						color: '#FF6600'
					},
					label: this.$createElement('strong', '中等')
				},
				60: {
					style: {
						color: '#FF3300'
					},
					label: this.$createElement('strong', '60')
				},
				70: {
					style: {
						color: '#FF0000'
					},
					label: this.$createElement('strong', '较高')
				},
				80: {
					style: {
						color: '#FF0000'
					},
					label: this.$createElement('strong', '80')
				},
				90: {
					style: {
						color: '#CC0000'
					},
					label: this.$createElement('strong', '高')
				},
				100: {
					style: {
						color: '#CC0000'
					},
					label: this.$createElement('strong', '100')
				}
			}
		}
	},
	mounted() {},
	created() {
		this.cname = this.$route.query.companyname
		if (this.$route.query.check) {
			this.checkshow = false
		}

		console.log(this.$route.query.id, 'psoitionanme');
		this.salaryChange()
		this.getDistrictList()
		this.getIndustryList()
		this.getFunctionList()
		this.getPostTypeAndSecurityNum()
		this.getTalentList()
		this.getWorkYearsList()
		this.getSalaryList()
		this.getWelfareList()
		this.getCompanyType()
		this.formInline.companyid = this.$route.query.id
		console.log(this.$route.query.positionid);
		if (this.$route.query.positionid) {
			this.formInline.positionid = this.$route.query.positionid
			console.log(this.formInline.positionid);
			this.status = this.$route.query.status
			console.log(this.status);
			this.getInfo()
			this.formInline.typeDisplay = true
			this.getPostModeling()
		}
		//年龄段
		this.getagelist();
		// console.log(this.formInline.positionid);
	},
	computed: {
		// 当岗位类型发生变化的时候触发计算属性，再触发监听者
		talenttypeChange: function() {
			console.log(this.formInline.talenttype)
			return this.formInline.talenttype
		},
		// 单人服务费用
		payNum: function() {
			if (this.formInline.wagetype === '1') {
				if (this.miniSalary && this.maxSalary) {
					this.formInline.miniwage = this.miniSalary * 1000
					this.formInline.maxwage = this.maxSalary * 1000
				}
				console.log();
				var aver = (+this.formInline.miniwage + +this.formInline.maxwage) / 2
				console.log(aver);
				if (aver >= 30000) {
					return 900;
				} else if (aver >= 20000 && aver < 30000) {
					return 800;
				} else if (aver >= 10000 && aver < 20000) {
					return 700;
				} else if (aver >= 6000 && aver < 10000) {
					return 600;
				} else if (aver < 6000 && aver != 0) {
					return 300;
				} else {
					return 0;
				}

			} else {
				let totalMoney = Math.floor(
					this.worktime * this.formInline.hourlywage * 0.05
				)
				return totalMoney || 0
			}
		}
	},

	watch: {
		// 当监听到这个发生变化时 遍历岗位类型里面的每一项option
		// 然后把newVaule和this.talentType[i].dictid对比，如果一样的话就把
		// this.talentType[i].remark2赋值给this.formInline.entryday和this.currentEntryday
		talenttypeChange(newVaule, oldVaule) {
			console.log(this.talentType)
			console.log(newVaule)
			for (let i = 0; i < this.talentType.length; i++) {
				if (this.talentType[i].dictid === newVaule + '') {
					// this.formInline.entryday = this.talentType[i].remark2
					this.currentEntryday = this.talentType[i].remark2
					return
				}
			}
		},
		payNum(newVaule, oldVaule) {
			this.timeNum = newVaule
		},
		'formInline.wagetype'(ewVaule, oldVaule) {
			if (this.formInline.wagetype === '2') {
				this.formInline.entryday = 0
			} else {
				// this.formInline.entryday = this.currentEntryday
			}
		}
	},

	methods: {
		currentXyshow() {
			this.xyshow = false
		},
		// 获取省市区数据
		getDistrictList() {
			this.$http.get('assets/citys.json').then(res => {
				this.districtOption = res.body.city
				this.districtOption.unshift({
					code: 999,
					subLevelModelList: [{
						code: 999,
						subLevelModelList: [{
							name: "全国",
							firstChar: "",
							code: 999
						}],
						name: "全国",
						firstChar: "q"
					}],
					name: "全国",
					firstChar: "q"
				})
				console.log(this.districtOption);
			})
		},
		// 获取所属行业数据
		getIndustryList() {
			this.$http.get('assets/select_Industry.json').then(res => {
				this.industrytypeOption = res.body.tradeList
			})
		},
		// 获取职能数据
		// getFunctionList() {
		//   this.$http.get("assets/function.json").then(res => {

		//     this.functionOption = res.body.position
		//   })
		// },
		// 获取岗位建模数据
		getPostModeling() {
			this.$ceshiAxios.post('/v1/release/findPosition', {
				positionid: this.$route.query.positionid
			}).then(res => {
				console.log(res)
				if (res.data.code === 1000) {
					let result = res.data.data.assessments
					let result2 = res.data.data.motives
					console.log(result2);
					console.log(result);
					this.direction[0].value = result.filter(item => item.id == 1)[0].number;
					this.direction[1].value = result.filter(item => item.id == 2)[0].number;
					this.direction[2].value = result.filter(item => item.id == 3)[0].number;
					this.direction[3].value = result.filter(item => item.id == 4)[0].number;
					this.direction[4].value = result.filter(item => item.id == 5)[0].number;
					this.direction[5].value = result.filter(item => item.id == 6)[0].number;
					this.direction[6].value = result.filter(item => item.id == 7)[0].number;
					this.direction[7].value = result.filter(item => item.id == 8)[0].number;
					this.direction[8].value = result.filter(item => item.id == 9)[0].number;
					this.direction[9].value = result.filter(item => item.id == 10)[0].number;
					this.direction[10].value = result.filter(item => item.id == 11)[0].number;
					this.direction[11].value = result.filter(item => item.id == 12)[0].number;
					this.motive[0].value = result2.filter(item => item.id == 1)[0].number;
					this.motive[1].value = result2.filter(item => item.id == 2)[0].number;
					this.motive[2].value = result2.filter(item => item.id == 3)[0].number;
					this.motive[3].value = result2.filter(item => item.id == 4)[0].number;
					this.motive[4].value = result2.filter(item => item.id == 5)[0].number;
					this.motive[5].value = result2.filter(item => item.id == 6)[0].number;
					this.motive[6].value = result2.filter(item => item.id == 7)[0].number;
					this.motive[7].value = result2.filter(item => item.id == 8)[0].number;
				}
			})
		},
		// 新的获取职能数据
		getFunctionList() {
			this.$http.get('assets/select_function.json').then(res => {
				this.functionOption = res.body.position
				console.log(this.functionOption)
			})
		},
		// 获取岗位类型和保障天数数据
		getPostTypeAndSecurityNum() {
			this.$ceshiAxios2
				.post('/v1/common/dict', {
					groupid: 'posttype'
				})
				.then(res => {
					console.log(res)
					this.talentType = res.data.data
					console.log(this.talentType)
					for (let i = 0; i < this.talentType.length; i++) {
						this.tempTalentType.push(this.talentType[i])
					}
				})
		},
		// 获取薪资条件数据
		getSalaryList() {
			this.$ceshiAxios2
				.post('/v1/common/dict', {
					groupid: 'salary'
				})
				.then(res => {
					console.log(res.data.data)
					if (res.data.code === 1) {
						this.salaryList = res.data.data
					}
				})
		},
		// 获取学历数据
		getTalentList() {
			this.$ceshiAxios2
				.post('/v1/common/dict', {
					groupid: 'education'
				})
				.then(res => {
					this.educationList = res.data.data
				})
		},
		// 获取工作年限数据
		getWorkYearsList() {
			this.$ceshiAxios2
				.post('/v1/common/dict', {
					groupid: 'worklife'
				})
				.then(res => {
					// console.log(res);
					this.WorkYearsList = res.data.data
				})
		},
		// 获取福利
		getWelfareList() {
			this.$ceshiAxios2
				.post('/v1/common/dict', {
					groupid: 'welfare'
				})
				.then(res => {
					this.welfareList = res.data.data
				})
		},
		// 获取公司类型和折扣
		getCompanyType() {
			// this.$ceshiAxios
			// 	.post('/v1/ent/company/baseDetail', {
			// 		companyid: sessionStorage.getItem('companyid')
			// 	})
			// 	.then(res => {
			// 		if (res.data.message === 'success.') {
			// 			let result = res.data.data
			// 			this.ishighquality = res.data.data.ishighquality
			// 			if (result.hasOwnProperty('ishighquality')) {
			// 				switch (result.ishighquality) {
			// 					case '0':
			// 						this.formInline.discount = 0.8
			// 						break
			// 					case '1':
			// 						this.formInline.discount = 0.9
			// 					default:
			// 						break
			// 				}
			// 			}
			// 		} else {
			// 			this.$message({
			// 				type: 'error',
			// 				message: '网络异常请稍后请重试'
			// 			})
			// 			// this.$router.push({
			// 			// 	path: '/post'
			// 			// })
			// 		}
			// 	})
		},
		// 获取岗位信息
		getInfo() {
			this.$ceshiAxios
				.post('/v1/recruit/stationInfo', {
					positionid: this.formInline.positionid
				})
				.then(res => {
					console.log(res)
					if ((res.data.message = 'success.')) {
						let result = res.data.data;
						this.formInline.selectDistricts = [Number(result.province), Number(result.city), Number(
							result.area)];
						this.formInline.companyid = result.companyid;
						console.log(result.companyid, 'result.companyid');
						this.formInline.wagetype = result.wagetype;
						console.log(result.wagetype);
						this.formInline.industrytype = result.industrytype;
						this.formInline.workday = result.workday;
						this.formInline.minage = result.minage;
						this.formInline.maxage = result.maxage;
						this.timeNum = result.fullpersonalintegral;
						this.demonstration = result.workingHours;
						console.log(result.workingHours, 'result.workingHours');
						if (this.formInline.wagetype === '2') {
							this.formInline.startTime = result.worktime.split('-')[0]
							this.formInline.endTime = result.worktime.split('-')[1]
							this.formInline.hourlywage = result.maxwage
							// this.formInline.workingHours = result.workingHours;
							this.formInline.hourlyState = result.hourlyState;
							let arr = result.workingHours.substring(1, result.workingHours.length - 1).split(',');
							if (result.hourlyState == '1') {
								this.checkList = arr;
								console.log(this.checkList);
							} else {
								this.demonstration = result.workingHours;
							}
							this.selectTime()
						}
						//年龄范围
						if (result.minage == '16' && result.maxage == '100') {
							this.formInline.minage = '不限'
							this.formInline.maxage = '不限'
						}
						if (result.maxage == '100') {
							this.formInline.maxage = '不限'
						}
						let b = []

						// this.industrytypeOption.forEach(el => {
						// 	el.subLevelModelList.forEach(element => {
						// 		if (element.code==this.formInline.industrytype) {
						// 			this.formInline.selectIndustrytypes=[
						// 				el.code,
						// 				+this.formInline.industrytype
						// 			]
						// 		}
						// 	})
						// })
						if (this.formInline.industrytype != undefined) {
							console.log(this.formInline.industrytype);
							for (var i in this.industrytypeOption) {
								for (var k in this.industrytypeOption[i].subLevelModelList) {
									if (this.industrytypeOption[i].subLevelModelList[k].code == this.formInline
										.industrytype) {
										b = [
											this.industrytypeOption[i].code,
											+this.formInline.industrytype
										]
									}
								}
							}
						}
						this.formInline.selectIndustrytypes = [...b]
						console.log(this.formInline.selectIndustrytypes, 'b');



						console.log(123, this.formInline.selectIndustrytypes)
						this.formInline.tradeid = result.tradeid
						let arr = [];
						[+result.remark1, +result.remark2, +result.tradeid].forEach(el => {
							arr.push(el)

						})
						this.formInline.selectFunctions = arr
						this.formInline.province = result.province // 省
						this.formInline.city = result.city // 市
						this.formInline.area = result.area // 区
						this.formInline.address = result.address // 工作地点
						this.formInline.positionname = result.positionname // 职位
						this.formInline.talenttype = result.talenttype // 岗位类型
						this.formInline.recruitment = +result.recruitment // 招收人数
						this.formInline.qualification = result.qualification // 学历要求
						this.formInline.worklife = result.worklife // 工作经验
						this.formInline.jobcontent = result.jobcontent // 岗位职责
						this.formInline.salaryStructure = result.salaryStructure // 薪资结构
						this.demonstration = eval(result.workingHours)
						this.miniSalary = result.miniwage / 1000
						this.maxSalary = result.maxwage / 1000
						// this.formInline.workduty = result.workduty // 岗位职责

						// if (+result.maxwage / 10000 > 10) {
						// 	this.miniSalary = +result.miniwage / 10000
						// 	this.maxSalary = +result.maxwage / 10000
						// 	this.flag = false
						// }
						this.formInline.offer =
							parseInt(result.miniwage) + '-' + parseInt(result.maxwage)
						this.salaryChange(this.formInline.offer)

						let welfareArr = result.welfare.split(';')
						for (let i = 0; i < welfareArr.length; i++) {
							this.welfares.push(welfareArr[i])
						}
						this.formInline.welfare = result.welfare //福利待遇
						this.formInline.paytype =
							result.paystatus === '0' ? '2' : result.paystatus // 支付类型
					} else {
						this.$message({
							message: res.data.message,
							type: 'error'
						})
					}
				})
		},
		// 这是不执行岗位建模请求的
		addPost1(formName) {
			console.log('add1');
			this.formInline.positionid = ''
			if (this.formInline.wagetype === '2') {
				this.formInline.entryday = 0
			}

			this.formInline.remark1 = localStorage.getItem('userid')
			this.formInline.companyid = this.$route.query.id;
			this.formInline.userid = localStorage.getItem('userid')
			console.log(this.formInline)
			this.$ceshiAxios
				.post('/v1/recruit/inputStationin', this.formInline)
				.then(res => {
					console.log(res)

					if (res.data.message === 'success.') {
						this.$message({
							message: '发布成功',
							type: 'success'
						})
						// this.$refs["addForm"].resetFields();
						// this.tempCity = "";
						this.formInline.positionid = res.data.data.positionid
						this.modeling('/v1/release/postRelease');
						this.linkTo("/home/pgindexassistant", {
							id: this.formInline.companyid,
							companyname: this.cname,
						});
					} else {
						this.selectTime()
						this.$message({
							message: res.data.message,
							type: 'error'
						})
					}
				})
		},
		// 这是执行岗位建模请求的
		addPost2(formName) {
			console.log('add2');
			if (this.formInline.wagetype === '2') {
				this.formInline.entryday = 0
			}
			this.formInline.remark1 = localStorage.getItem('userid')
			this.formInline.paytype = 2
			this.$ceshiAxios
				.post('/v1/recruit/inputStationin', this.formInline)
				.then(res => {
					console.log(res)
					if (res.data.message === 'success.') {
						this.$message({
							message: '发布成功',
							type: 'success'
						})
						// this.$refs["addForm"].resetFields();
						// this.tempCity = "";
						this.formInline.positionid = res.data.data.positionid
						console.log(res.data.data.positionid)
						this.modeling('/v1/release/postRelease');
						this.linkTo("/home/pgindexassistant", {
							id: this.formInline.companyid,
							companyname: this.cname,
						});
					} else {
						this.selectTime()
						this.$message({
							message: res.data.message,
							type: 'error'
						})
					}
				})
		},
		// 随便在这里发一下请求吧
		modeling(url) {
			console.log(sessionStorage.getItem('userid'))
			console.log(sessionStorage.getItem('companyid'))
			console.log(this.formInline.positionid)

			this.$ceshiAxios.post(url, {
					positionid: this.formInline.positionid,
					userid: '12c28ddeff0c4deba989b7778ef08be0',
					companyid: this.formInline.companyid,
					caozuo: this.direction[0].value,
					guihua: this.direction[1].value,
					jineng: this.direction[2].value,
					shiwu: this.direction[3].value,
					yishu: this.direction[4].value,
					faming: this.direction[5].value,
					renwu: this.direction[6].value,
					fuwu: this.direction[7].value,
					guankong: this.direction[8].value,
					kaituo: this.direction[9].value,
					jiaoji: this.direction[10].value,
					yingxiang: this.direction[11].value,
					caifu: this.motive[0].value,
					jiankang: this.motive[1].value,
					xiangshou: this.motive[2].value,
					gongzuo: this.motive[3].value,
					quanli: this.motive[4].value,
					chuangxin: this.motive[5].value,
					qinggan: this.motive[6].value,
					rongyu: this.motive[7].value
				})
				.then(res => {
					console.log(res)
				})
		},
		// ================================
		editPost(formName) {
			this.formInline.type = 1
			console.log('修改1');
			if (this.$route.query.reset) {
				this.formInline.type = 2
				this.formInline.remark1 = localStorage.getItem('userid')
			}
			let formData = this.formInline;
			formData.positionid = this.formInline.positionid
			console.log(formData);
			this.$ceshiAxios
				.post('/v1/recruit/inputStationin', formData)
				.then(res => {
					if (res.data.message === 'success.') {
						this.modeling('/v1/release/postUpdateRelease')
						this.$message({
							message: '修改成功',
							type: 'success'
						})
						// this.$refs["addForm"].resetFields();
						// this.tempCity = "";
						this.linkTo("/home/pgindexassistant", {
							id: this.formInline.companyid,
							companyname: this.cname,
						});
					} else {
						this.selectTime()
						this.$message({
							message: res.data.message,
							type: 'error'
						})
					}
				})
		},
		// ==================修改的判断============================
		editPost2(formName) {
			this.formInline.type = 1
			console.log('修改');
			let formData = this.formInline;
			delete formData.wagetype;
			console.log(formData);
			this.$ceshiAxios
				.post('/v1/recruit/inputStationin', formData)
				.then(res => {
					if (res.data.message === 'success.') {
						this.$message({
							message: '修改成功',
							type: 'success'
						})
						this.modeling('/v1/release/postUpdateRelease')
						// this.$refs["addForm"].resetFields();
						// this.tempCity = "";
						this.linkTo("/home/pgindexassistant", {
							id: this.formInline.companyid,
							companyname: this.cname,
						});
					} else {
						this.selectTime()
						this.$message({
							message: res.data.message,
							type: 'error'
						})
					}
				})
		},
		submitForm(formName) {
			if (this.formInline.positionname.length === 0) {
				this.$message({
					message: '职位不能为空',
					type: 'error'
				})
				window.scrollTo(0, 0)
				return
			}
			if (this.formInline.address.length === 0) {
				this.$message({
					message: '工作地点不能为空',
					type: 'error'
				})
				window.scrollTo(0, 0)
				return
			}
			if (this.formInline.recruitment.length === 0) {
				this.$message({
					message: '招聘人数不能为空',
					type: 'error'
				})
				window.scrollTo(0, 0)
				return
			}

			if (this.formInline.selectFunctions.length === 0) {
				this.$message({
					message: '职能人数不能为空',
					type: 'error'
				})
				window.scrollTo(0, 0)
				return
			}
			console.log(this.formInline.welfare);
			if (!this.formInline.welfare) {
				console.log(this.formInline.welfare);
				this.$message({
					message: '福利待遇不能为空',
					type: 'error'
				})
				window.scrollTo(0, 580)
				return
			}
			if (this.formInline.jobcontent.length === 0) {
				this.$message({
					message: '岗位描述不能为空',
					type: 'error'
				})
				window.scrollTo(0, 870)
				return
			}
			// if(this.formInline.workduty.length===0){
			//   this.$message({
			//     message: '任职要求不能为空',
			//     type: 'error'
			//   })
			//   window.scrollTo(0, 1100)
			//   return
			// }

			var integer = /^[0-9]*[1-9][0-9]*$/
			if (this.formInline.wagetype === '2') {
				if (this.formInline.workday === '0' || this.formInline.workday < '0') {
					this.$message({
						message: '工作天数必须大于0',
						type: 'error'
					})
					return
				}

				if (
					this.formInline.hourlywage === '0' ||
					this.formInline.hourlywage < '0'
				) {
					this.$message({
						message: '薪资待遇必须大于0',
						type: 'error'
					})
					return
				}

				if (this.formInline.endTime === '') {
					this.$message({
						message: '结束时间不能为空',
						type: 'error'
					})
					return
				}
			}
			if (
				this.formInline.recruitment === 0 ||
				this.formInline.recruitment < 0 ||
				this.formInline.recruitment === ''
			) {
				this.$message({
					message: '招聘人数必须大于或等于1人',
					type: 'error'
				})
				return
			}

			if (!this.flag && this.formInline.wagetype == '1') {
				if (this.miniSalary === '') {
					this.$message({
						message: '薪资待遇最小不能为空',
						type: 'error'
					})
					return
				}
				if (this.miniSalary < 10) {
					this.$message({
						message: '薪资待遇最小值不能小于10',
						type: 'error'
					})
					return
				}
				if (!integer.test(this.miniSalary)) {
					this.$message({
						message: '薪资待遇最小值只能输入大于等于10的整数',
						type: 'error'
					})
					return
				}
				if (this.maxSalary === '') {
					this.$message({
						message: '薪资待遇最大值不能为空',
						type: 'error'
					})
					return
				}


				if (this.miniSalary > this.maxSalary) {
					this.$message({
						message: '薪资待遇最小值不能大于最大值',
						type: 'error'
					})
					return
				}
				if (this.miniSalary === this.maxSalary) {
					this.$message({
						message: '薪资待遇最大值必须大于最小值',
						type: 'error'
					})
					return
				}
				if (!integer.test(this.maxSalary)) {
					this.$message({
						message: '薪资待遇最大值只能输入大于10的整数',
						type: 'error'
					})
					return
				}
				if (this.maxSalary * 1 > this.miniSalary * 1.3) {
					this.$message({
						message: '薪资待遇“最大值”不能大于“最小值”的30%',
						type: 'error'
					})
					return
				}
			}
			if (this.formInline.wagetype === '2' && !this.formInline.checked) {
				this.$message({
					message: '请阅读并同意非全日制用工积分扣除协议',
					type: 'error'
				})
				return
			}
			if (this.flag && this.formInline.wagetype == '1') {
				// if (this.formInline.offer === '') {
				//   this.$message({
				//     message: '请选择薪资待遇',
				//     type: 'error'
				//   })
				//   return
				// }
				console.log(111111111);
			}
			if (this.formInline.wagetype === '2') {
				this.formInline.miniwage = this.formInline.hourlywage
				this.formInline.maxwage = this.formInline.hourlywage
				this.formInline.worktime =
					this.formInline.startTime + '-' + this.formInline.endTime
			}
			if (this.formInline.maxage === '' && this.formInline.minage < 99) {
				this.$message({
					message: '请选择最大年龄',
					type: 'error'
				})
				return
			}
			if (this.formInline.minage == '不限' || this.formInline.minage == '100') {
				this.formInline.minage = '16'
				this.formInline.maxage = '100'
			}
			if (this.formInline.maxage == '不限') {
				this.formInline.maxage = '100'
			}

			let str1 =
				`本岗位招聘到的每位员工入职满${this.formInline.entryday||0}天，平台将收取${Math.floor((+this.payNum||0)*(+this.formInline.discount))}积分。`
			// str2 = "在免费体验中，您可以收到个人投递以及平台推荐的简历及内容，但无法查看简历姓名和联系方式，也无法邀约面试和沟通，建议您直接使用预付费模式！员工上班不满30一45天分文不收哦"
			if (!this.formInline.positionid) {
				// this.$confirm(this.formInline.paytype === '1' ? str1 : str2, this.formInline.paytype === '1' ? "温馨提示" : "您确定要免费体验吗？" , {
				this.$confirm(str1, '温馨提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					})
					.then(() => {
						this.$refs[formName].validate(valid => {
							if (valid) {
								if (!this.formInline.miniwage || !this.formInline.maxwage) {
									this.$message({
										message: '薪资待遇不能为空',
										type: 'warning'
									})
								}
								let num = this.formInline.recruitment
								// 计算积分和费用
								this.formInline.personalintegral = this.payNum
								this.formInline.discountpersonal =
									this.payNum * this.formInline.discount
								this.formInline.positionintegral = num * this.payNum
								this.formInline.discountposition =
									num * this.payNum * this.formInline.discount
								this.addPost1()
								// 在这里判断岗位建模选项个数有没有选对
								// let result = this.direction.filter(item => {
								// 	if (item.value > 0) {
								// 		return item
								// 	}
								// })
								// console.log(result.length)
								// let result2 = this.motive.filter(item => {
								// 	if (item.value > 0) {
								// 		return item
								// 	}
								// })
								console.log(result2.length)
								// if (result.length < 6 || result2.length < 8) {
								// 	this.$confirm('尚未完善岗位建模，平台将无法更加精确的推荐合适人才?', '提示', {
								// 		cancelButtonText: '继续完善',
								// 		confirmButtonText: '直接发布',
								// 		type: 'warning'
								// 	}).then(() => {
								// 		this.addPost1()
								// 	}).catch(() => {
								// 		this.$message({
								// 			type: 'info',
								// 			message: '继续完善'
								// 		});
								// 		this.activeName = '1'
								// 		window.scrollTo(0, 1300)
								// 	});

								// } else {
								// 	this.addPost2()
								// }
								this.addPost1()
							} else {
								this.addPost2()
							}
						})
					})
					.catch(error => {})
			} else if (this.formInline.positionid) {
				this.$confirm('您确定修改吗?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					})
					.then(() => {
						this.$refs[formName].validate(valid => {
							if (valid) {
								let num = this.formInline.recruitment
								// 计算积分和费用
								this.formInline.personalintegral = this.payNum
								this.formInline.discountpersonal =
									this.payNum * this.formInline.discount
								this.formInline.positionintegral = num * this.payNum
								this.formInline.discountposition =
									num * this.payNum * this.formInline.discount

								this.editPost()
								// 在这里判断岗位建模选项个数有没有选对
								// let result = this.direction.filter(item => {
								// 	if (item.value > 0) {
								// 		return item
								// 	}
								// })
								// console.log(result.length)
								// let result2 = this.motive.filter(item => {
								// 	if (item.value > 0) {
								// 		return item
								// 	}
								// })
								// console.log(result2.length)
								// if (result.length < 6 || result2.length < 8) {
								// 	this.$confirm('尚未完善岗位建模，平台将无法更加精确的推荐合适人才?', '提示', {
								// 		cancelButtonText: '继续完善',
								// 		confirmButtonText: '直接发布',
								// 		type: 'warning'
								// 	}).then(() => {
								// 		this.editPost()
								// 	}).catch(() => {
								// 		this.$message({
								// 			type: 'info',
								// 			message: '继续完善'
								// 		});
								// 	});

								// } else {
								// 	this.editPost2()
								// }
								console.log('修改执行');
							} else {
								this.editPost2()
							}
						})
					})
					.catch(error => {})
			} else if (this.formInline.positionid && this.status === '0') {
				this.$confirm(str1, '温馨提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					})
					.then(() => {
						this.$refs[formName].validate(valid => {
							if (valid) {
								let num = this.formInline.recruitment
								// 计算积分和费用
								this.formInline.personalintegral = this.payNum
								this.formInline.discountpersonal =
									this.payNum * this.formInline.discount
								this.formInline.positionintegral = num * this.payNum
								this.formInline.discountposition =
									num * this.payNum * this.formInline.discount
								// 在这里判断岗位建模选项个数有没有选对
								let result = this.direction.filter(item => {
									if (item.value > 0) {
										return item
									}
								})
								console.log(result.length)
								let result2 = this.motive.filter(item => {
									if (item.value > 0) {
										return item
									}
								})
								console.log(result2.length)
								// if (result.length < 6 || result2.length < 8) {
								// 	this.$confirm('尚未完善岗位建模，平台将无法更加精确的推荐合适人才?', '提示', {
								// 		confirmButtonText: '直接发布',
								// 		cancelButtonText: '继续完善',
								// 		type: 'warning'
								// 	}).then(() => {
								// 		this.$message({
								// 			type: 'success',
								// 			message: '发布成功'
								// 		});
								// 		this.addPost1()
								// 		this.addPost2()
								// 	}).catch(() => {
								// 		this.$message({
								// 			type: 'info',
								// 			message: '继续完善'
								// 		});
								// 	});

								// } else {
								// 	this.addPost2()
								// }
								this.addPost1()
							} else {
								return false
							}
						})
					})
					.catch(error => {})
			}
		},
		// 选择日期
		selectDate(data) {
			console.log(data)
			let arr = [];
			for (let i in data) {
				arr.push(data[i])
			}
			console.log()
			if (data.length > 0) {

				this.formInline.workingHours = JSON.stringify(arr);
				if (this.formInline.hourlyState == 1) {
					this.formInline.workday = `每周工作${data.length}个工作日`;
				} else {
					this.formInline.workday = data.length;
					this.formInline.workingHoursList = arr;
				}
			} else {
				this.formInline.workingHoursList = [];
				this.formInline.workday = 0;
			}
			console.log(this.formInline.workday);
		},
		goback() {
			// this.$router.go(-1)
			this.linkTo("/home/pgindexassistant", {
				id: this.formInline.companyid,
				companyname: this.cname,
			});
		},
		// 选择地市时触发
		districtChange(value) {
			// console.log(value);
			this.formInline.province = value[0]
			this.formInline.city = value[1]
			this.formInline.area = value[2]
			
			if(value[2]==undefined){
				this.formInline.area = '';
			}else {
				this.formInline.area = value[2]
			}
		},
		// 选择所属行业时触发
		industrytypeChange(value) {
			this.formInline.industrytype = value[1]
		},
		/**
		 * @description: 递归遍历职能选择出岗位类型
		 * @param {Number} count  递归次数 从0开始
		 * @param {Array} source   递归的数组
		 * @param {Array} codeArr  职能code数组
		 * @return:
		 */
		recursionGetTalentTypeObj(count, source, codeArr) {
			if (count > 2 || !source) return
			for (let i = 0, len = source.length; i < len; i++) {
				if (codeArr[count] === source[i].code) {
					if (count == 2) {
						// 这个岗位类型===this.functionOption[i].rank
						this.formInline.talenttype = source[i].rank
						return
					}
					count++
					this.recursionGetTalentTypeObj(
						count,
						source[i].subLevelModelList,
						codeArr
					)
				}
			}
		},
		// 选择职能时触发
		functionChange(value) {
			console.log(value)
			if (this.tempTalentType.length !== 0) {
				this.talentType = []
				for (let i = 0; i < this.tempTalentType.length; i++) {
					this.talentType.push(this.tempTalentType[i])
				}
			}
			this.formInline.tradeid = value[value.length - 1].toString()
			console.log(this.formInline.tradeid)
			this.recursionGetTalentTypeObj(0, this.functionOption, value);
		},

		// 选择岗位类型时触发
		itemList(val) {
			console.log(val)
			this.formInline.talenttype = val
		},
		// 选择薪资待遇时触发
		salaryChange(item) {
			
			
			 
			
			if (this.miniSalary == this.maxSalary) {
				  this.$message.warning('请输入正确的薪资范围！')
			}
			console.log(this.miniSalary);
			console.log(this.maxSalary);
			this.formInline.miniwage = this.miniSalary * 1000;
			this.formInline.maxwage = this.maxSalary * 1000;
			
			 
			
			
			if (this.formInline.maxwage <= 6000) {
				this.formInline.entryday = 30
			} else if (this.formInline.miniwage >= 6000 && this.formInline.maxwage <= 10000) {
				this.formInline.entryday = 60
				this.nowSave = 60
			} else if (this.formInline.miniwage >= 10000 && this.formInline.maxwage <= 20000) {
				this.formInline.entryday = 90
				this.nowSave = 90
			} else if (this.formInline.miniwage >= 20000 && this.formInline.maxwage <= 30000) {
				this.formInline.entryday = 120
				this.nowSave = 120
			} else if (this.formInline.maxwage >= 30000) {
				this.formInline.entryday = 150
				this.nowSave = 150
			}

		},
		// 选择工作时间触发
		selectTime(val) {
			// 计算时薪的时长
			if (this.formInline.startTime && this.formInline.endTime) {
				var st = this.formInline.startTime.split(':')[0]
				var sf = this.formInline.startTime.split(':')[1]
				this.startHour = st
				this.startmark = sf
				// console.log(1111,this.startHour);

				if (sf == 30) {
					st = +st + 0.5
				}
				var bt = this.formInline.endTime.split(':')[0]
				var bf = this.formInline.endTime.split(':')[1]

				this.endHour = bt
				this.endmark = bf
				// console.log(222222222, this.endHour);

				if (bf == 30) {
					bt = +bt + 0.5
				}
				this.worktime = bt - st
				// console.log(this.worktime);
				if (this.worktime >= 8 && this.worktime < 12) {
					this.worktime = this.worktime - 1
				}
				if (this.worktime >= 12) {
					this.worktime = this.worktime - 2
				}

				// console.log(this.worktime);
				// 时薪收取费用 = 时薪*时长*天数*10%，
				// console.log("ffffffff", this.formInline.worktime);
				// console.log(77777777777,this.startHour-this.endHour);
				// console.log(6666666666,this.endHour);
				// if ((this.startHour>this.endHour)) {
				//   this.$message({
				//     message: "开始时间不能大于结束时间",
				//     type: "error"
				//   })

				//   this.formInline.startTime=''
				//   return
				// }

				// if ((this.startHour=this.endHour)&&(this.startmark===this.endmark)){
				//   this.$message({
				//     message: "开始时间不能等于结束时间",
				//     type: "error"
				//   })
				//   this.formInline.startTime=''
				//   return
				// }
				// console.log(66666666);

				if (this.startHour - this.endHour > 0) {
					this.$message({
						message: '开始时间不能大于等于结束时间',
						type: 'error'
					})
					this.formInline.startTime = ''
					return
				}
				// else{
				if (
					this.startHour - this.endHour == 0 &&
					this.startmark - this.endmark >= 0
				) {
					this.$message({
						message: '开始时间不能大于等于结束时间',
						type: 'error'
					})
					this.formInline.startTime = ''
					return
				}
				// }
			}

			// this.startHour
			// this.startmark=sf
			// this.endHour=bt
			// this.endmark=bf

			// if(start===this.formInline.endTime ||this.formInline.startTime<this.formInline.endTime){
			//   this.$message({
			//     message: "开始时间必须小于结束时间",
			//     type: "error"
			//   })
			//   return
			// }
		},

		// 选择福利待遇时触发
		welfaresChange(w) {
			console.log(w);
			this.formInline.welfare = w.join(';')
		},
		userDefine() {
			if (this.flag) {
				this.formInline.entryday = 150
			} else {
				this.formInline.entryday = this.nowSave
			}
			console.log(this.flag)
			this.flag = !this.flag;
			(this.formInline.offer = ''), (this.formInline.miniwage = '')
			this.formInline.maxwage = ''
			this.miniSalary = ''
			this.maxSalary = ''
		},
		//获取最小年龄段
		getagelist() {
			for (var i = 16; i <= 101; i++) {
				if (i == 101) {
					i = '不限'
				}
				this.agelist.push(i)
			}
		},
		getmaxagelist() {
			this.maxagelist = []
			for (var i = this.formInline.minage + 1; i <= 100; i++) {
				if (i == 101) {
					i = '不限'
				}
				this.maxagelist.push(i)
			}
		},

		// 选择岗位类型时触发
		minageList(val) {
			// console.log(val);
			this.formInline.maxage = ''
			this.formInline.minage = val
			this.getmaxagelist()
			if (this.formInline.minage === 100 || this.formInline.minage === '不限') {
				this.disabledmax = true
				this.isShow = false
				this.formInline.maxage === '100'
			} else {
				this.disabledmax = false
				this.isShow = true
			}
		},

		wagetypeChange() {
			;
			(this.formInline.offer = ''), (this.formInline.miniwage = '')
			this.formInline.maxwage = ''
			this.miniSalary = ''
			this.maxSalary = ''
		},
		// 招聘人数取整
		proving() {
			this.formInline.recruitment = this.formInline.recruitment
				.toString()
				.replace(/[^\.\d]/g, '')
			this.formInline.recruitment = this.formInline.recruitment
				.toString()
				.split('.')[0]
		},

		currentMim(val) {
			this.miniSalary = parseInt(val)
		},
		currentMax(val) {
			if (this.miniSalary && parseInt(val) > parseInt(this.miniSalary * 1.3)) {
				this.maxSalary = parseInt(this.miniSalary * 1.3)
				this.$message({
					type: 'error',
					message: '最大薪资不能比最小薪资多30%以上！'
				})
			} else if (this.miniSalary == parseInt(val)) {
				this.maxSalary = parseInt(this.miniSalary + 1)
			} else {
				this.maxSalary = parseInt(val)
			}
		},
		LINKTOSERVICESTATEMENT() {
			// this.$router.push({
			//   path: '/jfxy'
			// })
			// this.xyshow = true
		}
	}
}
